package cn.xyinping.feign.clients;

import cn.xyinping.User;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author 27266
 * @desrciption 降级
 * @date 2021/11/18
 */
// 降级类都要实现FallbackFactory接口
@Component
public class UserFeignClientFallback implements FallbackFactory<UserFeignClient> {
    @Override
    public UserFeignClient create(Throwable throwable) {
        return new UserFeignClient() {
            @Override
            public User getById(Long id) {
                // 打印异常
                throwable.printStackTrace();
                // 该方法就是降级方法
                return new User(-1L,"降级工厂 ","系统繁忙");
            }
        };
    }
}
